package com.dubito.pattern.创建型模式.单例模式.懒汉式;

/**
 * @author liliang
 * @date 2020/8/26.
 */
public class SingleDemo {

    public static void main(String[] args) {
        NumThread threadA = new NumThread("线程 A");
        NumThread threadB = new NumThread("线程 B");
        threadA.start();
        threadB.start();
    }
}

class NumThread extends Thread {

    private String name;

    NumThread(String name) {
        this.name = name;
    }

    @Override
    public void run() {
        GlobalNum globalNum = GlobalNum.getInstance();
        for (int i = 0; i < 5; i++) {
            System.out.println(name + "第" + globalNum.getNum() + "次访问!");
            try {
                sleep(1000);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
